/**
 * 
 */
package org.mhz.sit.util;

import java.io.IOException;
import java.net.URL;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Paint;
import javafx.stage.Modality;
import javafx.stage.Stage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Mahan
 *
 * Confirm utility
 */
public class ConfirmUtil
{
    private static final Logger LOGGER = LoggerFactory.getLogger(ValidationUtil.class);
    
    private static Stage confirmStage;
    private static String confirmMessage;
    private static boolean confirmResult;
    
    /**
     * Private constructor
     */
    private ConfirmUtil()
    {
        
    }
    
    /**
     * Display a confirm dialog
     *
     * @param aMessage - the message to display
     */
    public static void displayConfirm(final String aMessage) 
    {
        try
        {
            setConfirmMessage(aMessage);
            
            final URL url = AlertUtil.class.getClassLoader().getResource(Constants.CONFIRM_FXML);
            final Parent root = FXMLLoader.load(url);
            
            confirmStage = new Stage();
            confirmStage.initModality(Modality.APPLICATION_MODAL);
            confirmStage.setTitle(Constants.CONFIRM_TITLE);
            final Scene scene = new Scene(root, Paint.valueOf(Constants.BACKGROUND));
            scene.getStylesheets().add(Constants.MAIN_STYLESHEET);
            confirmStage.setScene(scene);
            confirmStage.show();
        }
        catch (IOException ioEx)
        {
            LOGGER.error("Unable to open confirm dialog", ioEx);
        }
    }

    /**
     * @return Returns the confirmMessage.
     */
    public static String getConfirmMessage()
    {
        return confirmMessage;
    }

    /**
     * @param aConfirmMessage The confirmMessage to set.
     */
    public static void setConfirmMessage(final String aConfirmMessage)
    {
        confirmMessage = aConfirmMessage;
    }

    /**
     * @return Returns the confirmStage.
     */
    public static Stage getConfirmStage()
    {
        return confirmStage;
    }

    /**
     * @param aConfirmStage The confirmStage to set.
     */
    public static void setConfirmStage(final Stage aConfirmStage)
    {
        confirmStage = aConfirmStage;
    }

    /**
     * @return Returns the confirmResult.
     */
    public static boolean isConfirmResult()
    {
        return confirmResult;
    }

    /**
     * @param aConfirmResult The confirmResult to set.
     */
    public static void setConfirmResult(final boolean aConfirmResult)
    {
        confirmResult = aConfirmResult;
    }     
}
